new Ext.Application({
    name: 'IOrders',
    icon: 'icon.png',
    phoneStartupScreen: 'phone_startup.png',
    initViews: function() {
    	IOrders.views.MainView = new MainView();
    	IOrders.views.SyncView = new SyncView();
    	IOrders.views.SettingsView = new SettingsView();
    },
    onClientBtnTap: function() {
    	this.viewport.hide();
    	IOrders.views.Navigator.show();
    },
    launch: function() {        
    	this.initViews();
        document.body.addEventListener('touchstart', function(e) {e.preventDefault();}, false);        
        this.viewport = new Ext.TabPanel({
            fullscreen: true,
            cardSwitchAnimation: {type: 'slide', duration: 400},
            tabBar: {
                dock: 'bottom',
                layout: {
                    pack: 'center'
                },
                items: [{text: 'Клиенты', handler: this.onClientBtnTap, scope: this}]
            },
            items: [
                IOrders.views.MainView,
				IOrders.views.SyncView,
				IOrders.views.SettingsView
            ]
        });
        dataSync.ajax = new Ext.data.Connection({
            url: location.protocol + '//' + location.host
                + location.pathname.slice(0, location.pathname.substr(0, location.pathname.length - 1).lastIndexOf('/'))
                + '/XML/?config=datasync',
            listeners: {
            	scope: IOrders.views.SyncView,
                beforerequest: IOrders.views.SyncView.newNote,
                requestcomplete: IOrders.views.SyncView.successNote,
                requestexception: IOrders.views.SyncView.failureNote
            }
        });

        dataSync.db = dbinit('IOrders');
        dataSync.credentials.view = 'iorders';        
        dataSync.loadSchema(dbSchema);
        
        createModels();
                
        document.title = document.title + ' ' + dbSchema.version;        
        settingsStore.load();        
    }
});